package Student;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class TestStudent {
    public static void main(String[] args) {
        ArrayList<Student> stu=new ArrayList<>();
        Student stu1=new Student("张三",20,90.0f);
        Student stu2=new Student("李四",22,90.0f);
        Student stu3=new Student("王五",20,95.0f);
        Student stu4=new Student("赵六",22,100.0f);
        Student stu5=new Student("田七",26,87.0f);
        stu.add(stu1);
        stu.add(stu2);
        stu.add(stu3);
        stu.add(stu4);
        stu.add(stu5);
   /*根据成绩做降序排序，如果成绩相同，那在成绩排序的基础上按照年龄升序排序。*/
        Collections.sort(stu, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int result=(int)(o2.getScore()-o1.getScore());
                if (result==0){
                    return o1.getAge()- o2.getAge() ;
                }
                return result;
            }
        });
        System.out.println("姓名\t\t年龄\t\t成绩");
     for (Student s:stu){
         Student n=(Student)s;
         System.out.println(n.getName()+"\t\t"+n.getAge()+"\t\t"+n.getScore());
     }
}
  }